<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view('common/head');?>

<?php $this->load->view('common/header');?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar');?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs');?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set');?>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" id="form" name="form" action="<?php echo site_url(X_URL.'group/update');?>" method="post">
						<?php echo csrf_hidden();?>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 用户组名 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="title" id="title" placeholder="用户组名"
                                           class="col-xs-10 col-sm-5" value="<?php echo $group['title']?>">
                                    <input type="hidden" name="id" id="id" value="<?php echo $group['id']?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">用户组名称，不能为空。</span>
											</span>
                                </div>
                            </div>
                            <?php if($group['id'] != 1){?>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 是否启用 </label>
                                <div class="control-label no-padding-left col-sm-1">
                                    <label>
                                        <input name="status" id="status"
                                        <?php if($group['status'] == 1):?> checked="checked"<?php endif;?>
                                        class="ace ace-switch ace-switch-2" type="checkbox" />
                                        <span class="lbl"></span>
                                    </label>
                                </div>
                                <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">YES，启用；NO，禁用</span>
										</span>
                            </div>
                             <?php }else{ ?>
                                <input name="status" id="status" value ="on" type="hidden" />
                            <?php } ?>
                            <div class="space-4"></div>
                            <?php if($group['id'] != 1){?>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                        权限选择 </label>
                                    <div class="col-sm-9">
                                        <div class="col-sm-10">
                                            <?php
                                            if(isset($rule)) {
                                                foreach ($rule as $key => $v) {
                                                    ?>
                                                    <div class="row">
                                                        <div class="widget-box">
                                                            <div class="widget-header">
                                                                <h4 class="widget-title">
                                                                    <label>
                                                                        <input name="rules[]"
                                                                               class="ace ace-checkbox-2 father" <?php if (in_array($v['id'], $group['rules'])) {
                                                                            echo 'checked="checked"';
                                                                        }; ?>
                                                                               type="checkbox"
                                                                               value="<?php echo $v['id'] ?>"/>
                                                                        <span class="lbl"> <?php echo $v['title'] ?></span>
                                                                    </label>
                                                                </h4>
                                                                <div class="widget-toolbar">
                                                                    <?php if (!empty($v['children'])): ?>
                                                                        <a href="#" data-action="collapse">
                                                                            <i class="ace-icon fa fa-chevron-up"></i>
                                                                        </a>
                                                                    <?php endif; ?>
                                                                </div>
                                                            </div>
                                                            <?php if (!empty($v['children'])): ?>
                                                                <div class="widget-body">
                                                                    <div class="widget-main row">
                                                                        <?php foreach ($v['children'] as $key => $vv) { ?>
                                                                            <label class="col-xs-2" style="width:160px;">
                                                                                <input name="rules[]" class="ace ace-checkbox-2 children" <?php if (in_array($vv['id'], $group['rules'])) {
                                                                                    echo 'checked="checked"';}; ?> type="checkbox" value="<?php echo $vv['id'];?>"/>
                                                                                <span class="lbl"> <?php echo $vv['title'] ?></span>
                                                                            </label>
                                                                            <?php if (!empty($vv['children'])): ?>
																				<?php foreach ($vv['children'] as $key => $vvv) { ?>
																					<label class="col-xs-2"
																						   style="width:160px;">
																						<input name="rules[]" class="ace ace-checkbox-2 children" <?php if (in_array($vvv['id'], $group['rules'])) {
																							echo 'checked="checked"';}; ?> type="checkbox" value="<?php echo $vvv['id'] ?>"/>
																						<span class="lbl"> <?php echo $vvv['title'] ?></span>
																					</label>
																				<?php } ?>
																			<?php endif; ?>
																		<?php }; ?>
                                                                    </div>
                                                                </div>
                                                            <?php endif; ?>
                                                        </div>
                                                    </div>
                                                <?php } ?>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            <?php };?>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    </div><?php $this->load->view('common/footer');?>


<?php $this->load->view('common/footerjs');?>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(".children").click(function () {
        $(this).parent().parent().parent().parent().find(".father").prop("checked", true);
    })
    $(".father").click(function () {
        if (this.checked) {
            $(this).parent().parent().parent().parent().find(".children").prop("checked", true);
        } else {
            $(this).parent().parent().parent().parent().find(".children").prop("checked", false);
        }
    })
    $(".submit").click(function () {
        var title = $("#title").val();
        if (title == '') {
            bootbox.dialog({
                message: "用户组名称不能为空。",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
            return;
        }
        $('#form').submit();

    })
</script>
</body>
</html>
